home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 1996 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  5.9 KB

  1. Path: zetnet.co.uk!demon!redrobe.demon.co.uk
  2. From: Mike@Redrobe.demon.co.uk (Mike)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: Scalable GUI's
  5. Date: 25 Jan 96 15:44:58 +0000
  6. Message-ID: <5650.6598T944T2930@Redrobe.demon.co.uk>
  7. References: <4e67fm$544@columbia.acc.brad.ac.uk>
  8. NNTP-Posting-Host: redrobe.demon.co.uk
  9. X-NNTP-Posting-Host: redrobe.demon.co.uk
  10. X-Newsreader: THOR 2.22 (Amiga;TCP/IP)
  11.  
  12.  
  13. Hi, LA GUESTn , on 24-Jan-96 21:14:30 you scribbled....
  14. >I wish to produce GUI's that are font sensitive without using somebody elses
  15. >GUI libraries or GUI designers. The way I want to do it is to have functions
  16. >which will scale an (x,y) coord or width/height values by a standard
  17. >value...if anyone has achieved this could they help me out?
  18.  
  19. >Any language (but asm - too difficult to follow!) is acceptable.
  20.  
  21. Here's some code from one of my programs ( the GUI is from GadToolsBox,
  22. so some bits may be from that...))
  23.  
  24. Its not that elegant but hey, its clean and bug-free (AFAIK anyway ;)
  25.  
  26. --
  27. int ResizeGadgets(int newwidth,int newheight)
  28. {
  29.         struct IntuiMessage     *m;
  30.         int                     (*func)();
  31.         BOOL                    running = TRUE;
  32.         struct Gadget   *g;
  33.         UWORD           lc, tc;
  34.         int count=0;
  35.         long double xscale=1.0,yscale=1.0;
  36.         struct NewGadget        ng;
  37.         long lasty=0;
  38.  
  39.                                 if ( ! ( g = CreateContext( &Project0GList )))
  40.                                         return( 1L );
  41.  
  42.                                 xscale = ((long double)(newwidth)) /(long
  43. double)(ww+OffX);
  44.                                 yscale = ((long double)(newheight)) /(long
  45. double)(wh+OffY);
  46.                                 //printf("Scale = (X) %f : (Y)
  47. %f\n",xscale,yscale);
  48.                                 for( lc = 0, tc = 0; lc < Project0_CNT; lc++ )
  49. {
  50.  
  51.                                         CopyMem((char * )&Project0NGad[ lc ],
  52. (char * )&ng, (long)sizeof( struct NewGadget ));
  53.  
  54.                                         ng.ng_VisualInfo = VisualInfo;
  55.                                         ng.ng_TextAttr   = Font;
  56.                                         ng.ng_LeftEdge   = (long double)(OffX
  57. + (ComputeX( ng.ng_LeftEdge )) * (long double)xscale);
  58.                                         if ((Project0GTypes[lc] ==
  59. LISTVIEW_KIND)&&(yscale>1.0))
  60.                                                 ng.ng_TopEdge    = lasty + 12;
  61.                                         else
  62.                                                 ng.ng_TopEdge    = (long
  63. double)(OffY + (ComputeY( ng.ng_TopEdge )) * (long double)yscale);
  64.  
  65.                                         if ( Project0GTypes[ lc ] !=
  66. GENERIC_KIND ) {
  67.                                                 ng.ng_Width = (UWORD)( (long
  68. double)ComputeX( ng.ng_Width) * (long double)xscale);
  69.                                                 if ((Project0GTypes[lc] !=
  70. LISTVIEW_KIND)&&(yscale>1.0))
  71.                                                         ng.ng_Height
  72. =(UWORD)((long double) ComputeY( ng.ng_Height) );
  73.                                                 else
  74.                                                         ng.ng_Height =
  75. (UWORD)((long double) ComputeY( ng.ng_Height) * (long double)yscale);
  76.                                                 }
  77.                                         if (((ng.ng_TopEdge + ng.ng_Height) >
  78. lasty) && (Project0GTypes[lc] != LISTVIEW_KIND))
  79.                                                 lasty = ng.ng_TopEdge +
  80. ng.ng_Height;
  81.                                         Project0Gadgets[ lc ] = g =
  82. CreateGadgetA((ULONG)Project0GTypes[ lc ], g, &ng, ( struct TagItem *
  83. )&Project0GTags[ tc ] );
  84.  
  85.                                         if ( Project0GTypes[ lc ] ==
  86. GENERIC_KIND ) {
  87.                                                 g->Flags             |=
  88. GFLG_GADGIMAGE | GFLG_GADGHIMAGE;
  89.                                                 g->Activation        |=
  90. GACT_RELVERIFY;
  91.                                                 g->GadgetRender       =
  92. (APTR)getImage;
  93.                                                 g->SelectRender       =
  94. (APTR)getImage;
  95.                                         }
  96.  
  97.                                         while( Project0GTags[ tc ] ) tc += 2;
  98.                                         tc++;
  99.  
  100.                                         if ( NOT g )
  101.                                                 return( 2L );
  102.                                 }
  103. }
  104.  
  105. void    ResizeWindow(int newwidth,int newheight)
  106.         {
  107.         struct IntuiMessage     *m;
  108.         int                     (*func)();
  109.         BOOL                    running = TRUE;
  110.         struct Gadget   *g;
  111.         UWORD           lc, tc;
  112.         int count=0;
  113.         long double xscale=1.0,yscale=1.0;
  114.         struct NewGadget        ng;
  115.  
  116.                                 StoreForResize();
  117.                                 RemoveGList(Project0Wnd,Project0GList,-1);
  118.                                 FreeGadgets( Project0GList );
  119.                                 Project0GList=NULL;
  120.  
  121.                                 ResizeGadgets(newwidth,newheight);
  122.  
  123.                                 SetAPen(Project0Wnd->RPort,0L);
  124.                                 RectFill(Project0Wnd->RPort,Project0Wnd-
  125. >BorderLeft,
  126.                                          Project0Wnd->BorderTop,
  127.                                          newwidth-Project0Wnd->BorderRight-1,
  128.                                          newheight-Project0Wnd->BorderBottom-
  129. 1);
  130.  
  131.                                 RefreshWindowFrame(Project0Wnd);
  132.                                 AddGList(Project0Wnd,Project0GList,-1,-
  133. 1,NULL);
  134.                                 UserSetupWindow();
  135.                                 RefreshGList(Project0GList,Project0Wnd,NULL,-
  136. 1);
  137.                                 GT_RefreshWindow(Project0Wnd,NULL);
  138. }
  139. }
  140.  
  141. --
  142.  
  143.  
  144.  
  145. Mike
  146.  
  147. --
  148. ---------------------------------------------------------------------------
  149. Mike Redrobe - Mike@Redrobe.demon.co.uk         MikeRR on #Amiga
  150. ---------------------------------------------------------------------------
  151.  
  152.